<?php

class Fx_Wrapper {
	
	private $wrapperId      = '';
	
	private $wrapperClasses = array();
	
	private $startWrapper   = '';	
	
	private $endWrapper     = '';
	
	function __construct($id = '', $start = '<div>', $end = '</div>') {
		$this->wrapperId    = $id;
		$this->startWrapper = $start;
		$this->endWrapper   = $end;
	}
	
	public function getId() {
		return $this->wrapperId;	
	}
	
	public function setid($id) {
		$this->wrapperId = $id;	
		return $this;
	}
	
	public function getClasses() {
		return $this->wrapperClasses;	
	}
	
	public function addClass($className) {
		if (!in_array($className, $this->getClasses()) || !array_key_exists($className, $this->getClasses())) {
			$this->wrapperClasses[$className] = $className;		
		}
		return $this;
	}
	
	public function removeClass($className) {
		if (in_array($className, $this->getClasses()) && array_key_exists($className, $this->getClasses())) {
			unset($this->wrapperClasses[$className]);		
		}
		return $this;
	}
	
	public function changeClass($currentClass, $newClass) {
		if (in_array($currentClass, $this->getClasses()) && array_key_exists($currentClass, $this->getClasses())) {
			$this->removeClass($currentClass);
			$this->addClass($newClass);
		}	
		return $this;
	}
	
	public function getStartWrapper() {
		$wrapper = str_replace('>', '', $this->startWrapper);
		if ($id = $this->getId()) {
			$wrapper .= ' id="' . $id . '"';	
		}
		if (count($classes = $this->getClasses()) > 0) {
			$wrapper .= ' class="';	
			foreach ($classes as $class) {
				$wrapper .= $class . " ";
			}
			$wrapper = substr($wrapper, 0, strlen($wrapper) - 1) . '"';
		}
		return $wrapper . '>';	
	}
	
	public function getEndWrapper() {
		return $this->endWrapper;	
	}
}